#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
@Date    ：2025/1/7 18:26:17
@Description:
"""
import json

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import StaticCredentialsProvider
from pathlib import Path
# 从环境变量中获取访问凭证。运行本代码示例之前，请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuthV4(StaticCredentialsProvider("LTAI5tG5HJqL8Y65bJYddpVc","wAQGXIWfGKfY4E6xGzPzDKTZz6s6FO"))

# 填写Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"

# 填写Endpoint对应的Region信息，例如cn-hangzhou。注意，v4签名下，必须填写该参数
region = "cn-hangzhou"
# 填写Bucket名称，例如examplebucket。
bucketName = "2514data"
# 创建Bucket实例，指定存储空间的名称和Region信息。
bucket = oss2.Bucket(auth, endpoint, bucketName, region=region)

def get_tem_url(key):
    return bucket.sign_url('GET', key, expires=3600)


def put_object(local_file_path,key):

    # 使用put_object_from_file方法将本地文件上传至OSS
    res = bucket.put_object_from_file(key, local_file_path)
    print(res)




